<?php
/**
 * Created by Dumitru Russu
 * User: developer
 * Date: 11/7/12
 * Time: 11:13 AM
 * To change this template use File | Settings | File Templates.
 */
class Db_Payments_ProjectsPaymentMethods extends Common {
	protected static $tableName = TAB_PROJECT_PAYMENT_METHODS;
	protected static $dbFields = array(
		'id',
		'ppm_project_id',
		'ppm_payment_method_id',
		'ppm_invoice_note',
		'ppm_invoice_text',
		'ppm_email_note',
		'ppm_email_text',
		'ppm_show_on_page',
		'ppm_position',
		'deleted'
	);

	/**
	 * @var Db_Payments_ProjectsPaymentMethods
	 */
	public $objectArray;

	public static $positionField = 'ppm_position';

	public $id;
	public $ppm_project_id;
	public $ppm_payment_method_id;
	public $ppm_invoice_note;
	public $ppm_invoice_text;
	public $ppm_email_note;
	public $ppm_email_text;
	public $ppm_show_on_page;
	public $ppm_position;
	public $deleted;


	function __construct($value = null, $fieldName = null) {
		parent::__construct($value, $fieldName);
	}

	/**
	 * @static
	 * @param $projectId
	 * @return array|bool
	 */
	public static function getProjectPaymentMethodsByProjectId($projectId) {
		$sql = "SELECT *, `ppm`.`id` AS `ppm_id` FROM ?f AS `ppm`
				INNER JOIN ?f AS `pm` ON `pm`.`id` = `ppm`.`ppm_payment_method_id`
				WHERE `pm`.`deleted` = 0 AND `ppm`.`deleted` = 0 AND `ppm`.`ppm_project_id` = ?
				ORDER BY `ppm`.`ppm_position` ASC";
		return self::find($sql, self::$tableName, TAB_PAYMENT_METHODS, $projectId);
	}
}
